package com.springbook;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class BikeValidator implements Validator {


	public boolean supports(Class arg0) {
		return arg0.equals(Bike.class);
	}

	public void validate(Object o, Errors err) {
		Bike b = (Bike) o;
		if (b==null) err.rejectValue("bike", "Error!",null, "Bike cannot be null");
		String manufacturer=b.getManufacturer();
		String model=b.getModel();
		if (manufacturer==null||"".equals(manufacturer)) err.rejectValue("manufacturer", "Value Not Present", null, "manufacturer must be set");
		if (model==null||"".equals(model)) err.rejectValue("model", "Value Not Present", null, "model must be set");
	}

}
